#include <stdio.h>
#include <stdlib.h>

typedef int ElementType;
#define MinData -1

typedef struct HeapStruct*PriorityQueue;
struct HeapStruct
{
    ElementType*Elements;
    int        Capacity;
    int        Size;
};

PriorityQueue Initialize(int MaxElements); /* details omitted */

void PercolateUp(int p,PriorityQueue H);
void PercolateDown(int p,PriorityQueue H);

void Insert(ElementType X,PriorityQueue H)
{
    int p=++H->Size;
    H->Elements[p]=X;
    PercolateUp(p,H);
}

ElementType DeleteMin(PriorityQueue H)
{
    ElementType MinElement;
    MinElement=H->Elements[1];
    H->Elements[1]=H->Elements[H->Size--];
    PercolateDown(1,H);
    return MinElement;
}

int main()
{
    int           n,i,op,X;
    PriorityQueue H;
    
    scanf("%d",&n);
    H=Initialize(n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&op);
        switch(op)
        {
            case 1:scanf("%d",&X);
                Insert(X,H);
                break;
            case 0:printf("%d ",DeleteMin(H));
                break;
        }
    }
    printf("\nInside H:");
    for(i=1;i<=H->Size;i++)
        printf(" %d",H->Elements[i]);
    return 0;
}

/* Your function will be put here */
void swap(ElementType*a,ElementType*b)
{
    ElementType c=*a;
    *a=*b;
    *b=c;
}
void PercolateUp(int p,PriorityQueue H)
{
    while(p!=1)
    {
        if(H->Elements[p]<H->Elements[p>>1])
            swap(&H->Elements[p],&H->Elements[p>>1]);
        else
            break;
        p>>=1;
    }
}
void PercolateDown(int p,PriorityQueue H)
{
    while((p<<1)<H->Size)
    {
        int temp=p;
        if(H->Elements[p]>H->Elements[(p<<1)])
            temp=(p<<1);
        
        if((((p<<1)+1)<=H->Size)&&(H->Elements[temp]>H->Elements[((p<<1)+1)]))
            temp=((p<<1)+1);
        if(temp==p)
            break;
        else
        {
            swap(&H->Elements[p],&H->Elements[temp]);
            p=temp;
        }
    }
}